package com.itheima.executorService;

import java.util.Arrays;
import java.util.concurrent.Callable;

// 创建线程的方式3：实现Callable接口，实现call()方法，创建线程对象，调用start()方法
public class MyCallable implements Callable<int[]> {

    public int n;
    public MyCallable(int n) {
        this.n = n;
    }
    public int[] call() throws Exception {
        System.out.println("PrimeThread3正在计算素数1-" + n + "...");
        int[] arr = new int[n];
        int count = 0;
        for (int i = 2; i <= n; i++) {
            boolean isPrime = true;
            for (int j = 2; j * j <= i; j++) {
                if (i % j == 0) {
                    isPrime = false;
                    break;
                }
            }
            if (isPrime) {
                arr[count++] = i;
            }
        }
        int[] res = new int[count];
        res = Arrays.copyOf(arr, count);
        return res;
    }
}